package com.fdb.efp.esb.service.impl.sed.tax;

import com.fdb.efp.esb.common.client.resp.EsbRespServiceBean;
import com.fdb.efp.esb.common.constant.EsbBizEnums;
import com.fdb.basic.framework.core.util.TraceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.fdb.basic.framework.core.constant.ESBConstant;
import com.fdb.basic.framework.core.exception.ESBException;
import com.fdb.efp.esb.service.bo.req.sed.tax.ReqTaxIssMsgQryBean;
import com.fdb.efp.esb.service.bo.resp.sed.tax.RespTaxIssMsgQryBean;
import com.fdb.efp.esb.service.client.ESBClientFactory;
import com.fdb.efp.esb.service.facade.sed.tax.TaxIssueMsgQueryService;

/**
 * 需求编号：【2019D0519】（业务提的需求编号）
 * 问题编号：【xxxxxxx】（若不是因为修复问题而新增该类，则留空）
 * 开发人员：qiuyf
 * 创建日期：2019年5月6日 下午3:07:53
 * 功能描述：获贷信息查询（风险防控）接口实现
 * 	50130003 (涉税信息查询) 【本服务用于涉税信息查询】
 * 	03 (纳税信息查询) 【本场景用于卡中心通过互联网开放平台向税务局查询客户纳税详细信息明细】
 */
@Service("taxIssueMsgQueryService")
public class TaxIssueMsgQueryServiceImpl implements TaxIssueMsgQueryService {

	private static Logger logger = LoggerFactory.getLogger(TaxIssueMsgQueryServiceImpl.class);
	
	@Override
	public RespTaxIssMsgQryBean taxIssueMsgQuery(ReqTaxIssMsgQryBean reqTaxIssMsgQryBean) throws ESBException {
		logger.info("======>获贷信息查询（风险防控）接口【"+ TraceUtil.getTraceId() +"_50130003_03】开始<======");
		EsbRespServiceBean esbRespServiceBean = null;
		RespTaxIssMsgQryBean respTaxIssMsgQryBean = null;
		try {
			esbRespServiceBean = ESBClientFactory.buildClient()
					.withBody(reqTaxIssMsgQryBean)
					.withTradeNo(ESBConstant.TRADE_CODE_50130003)
					.withScene(ESBConstant.SCENE_NO_03)
					.create()
					.sendAndReceive();
			if(EsbBizEnums.RetCodeEnum.SUCCESS.getVALUE().equals(esbRespServiceBean.getSysHead().getRetInfArry().get(0).getRetCd())) {
				respTaxIssMsgQryBean = esbRespServiceBean.getBody(RespTaxIssMsgQryBean.class);
			}else {
				throw new  ESBException("开放平台发生异常，返回信息为：" + esbRespServiceBean.getSysHead().getRetInfArry().toString());
			}
			logger.info("调用获贷信息查询（风险防控）接口【50130003_03】结束，返回信息：" + JSONObject.toJSONString(respTaxIssMsgQryBean));
		} catch (ESBException e) {
			logger.error("调用获贷信息查询（风险防控）接口【50130003_03】出现异常：" + e.getMessage());
			throw new ESBException("调用获贷信息查询（风险防控）接口【50130003_03】出现异常：" + e.getMessage());
		}finally {
			logger.info("======>获贷信息查询（风险防控）接口【"+ TraceUtil.getTraceId() +"_50130003_03】结束<======");
		}
		return respTaxIssMsgQryBean;
	}

}
